
package com.smartthinking.CICPNL.home.activity;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Toast;

import com.smartthinking.CICPNL.R;

public class DestinoDocumento extends Activity {
	private Intent intent;
	public String pdf_URL;
	
	
	public void voidFinish(View V) {
		finish();

	}
		
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.ui_destino_doc);

		Bundle extras = getIntent().getExtras();
		if (extras!=null){
			pdf_URL = extras.getString("pdf_URL");
			Log.i("pdf_URL", ""+pdf_URL);
			
			File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Pediatria/"+pdf_URL);
			
			Uri path = Uri.fromFile(file); 
            Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
            pdfIntent.setDataAndType(path, "application/pdf");
            pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            try{
                startActivity(pdfIntent);
            }catch(Exception e){
            	Toast.makeText(getApplicationContext(), R.string.st_no_application_available_to_view_pdf, Toast.LENGTH_LONG).show();
            }
			
//			Intent intent = new Intent(Intent.ACTION_VIEW);
//			intent.setDataAndType(Uri.fromFile(file),"application/pdf");
//			intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
//			startActivity(intent);
			
//			Intent intent = new Intent(Intent.ACTION_VIEW);
//			intent.setDataAndType(Uri.parse(url), "application/pdf");
//			
			//PENDIENTE COMO ABRIR UN DOC PDF?
		}
		
	}

	
}
